Monitor = function(){
	this.param = {};
	this.self = this;
};

Monitor.prototype = {
	
	/* 设置参数 */	
	setParam:function(param){
		this.param = param;
		
		if(this.param.esb == undefined){
			return;
		}
		
		//是否路径填充
		if(this.param.esb.isPathFill == undefined){
			this.param.esb.isPathFill = true;
		}
		
		//填充前面路径
		if(this.param.esb.classPath){
			if(this.param.esb.isPathFill){
				if(this.param.esb.classPath.indexOf("cn.lily.esb.monitor.control.node.") == -1){
					this.param.esb.classPath = "cn.lily.esb.monitor.control.node."+this.param.esb.classPath
				}
			}
		}
		
		if(this.param.esb.serviceCode == undefined){
			this.param.esb.serviceCode = "monitor";
		}	
		
	},
	
	/* 补充参数 */
	appendParam:function(msg,e){
		eval(MUtil.getObject(msg, "this.param.", "msg."));
	},

	/* 装载HTML页面 */
	loadHTML:function(){
		
		if(this.param.esb){
			//获取数据
			var msgExcute = new MonitorMsg();
			
			//设置额外参数
			var param = "{'serviceCode':this.param.esb.serviceCode,"
					    +"'traceId':this.param.esb.traceId,"
					    +"'url':this.param.esb.url,"
					    +"'classPath':this.param.esb.classPath";
			if(this.param.esb.monitorAppAuth != undefined){
				param += ",'monitorAppAuth':'"+this.param.esb.monitorAppAuth+"'";
			}
			if(this.param.esb.param !=undefined) {
				param += ",'param':{";
				for(var p in this.param.esb.param){
					param += "'"+p+"':'" + this.param.esb.param[p] +"',";
				}
				
				param = param.substring(0,param.length-1);
				
				param += "}";
			}
			
			param += "}";
			
			msgExcute.setParam(eval("("+param+")"));
			msgExcute.post();
		}
		
		if(this.param.web){
			//表格数据装载
			if(this.param.web.viewType == "table"){
				this.loadTable(msgExcute.rsp.body);
			}
			
			//表格整体装载
			if(this.param.web.viewType == "fixTable"){
				this.loadFixTable(msgExcute.rsp.body.table);
			}
			
			//标签页装载
			if(this.param.web.viewType == "tab"){
				this.loadTab(msgExcute.rsp.body.tab);
			}
			
			//装饰组件装载
			if(this.param.web.viewType == "tag"){
				this.loadTag(msgExcute.rsp.body.tag);
			}
			
			//二列表装载
			if(this.param.web.viewType == "mapTable"){
				this.loadMap(msgExcute.rsp.body.mapTable);
			}
			
			//系统多选表装载
			if(this.param.web.viewType == "navTable"){
				this.loadNav(msgExcute.rsp.body.table)
			}
			
			//通用按钮注册
			if(this.param.web.button !=undefined){
				regCommonClick();
			}
			
			//监控独有参数
			if(this.param.web.reload != undefined){
				regReloadCache(this.param.web.reload);
			}
			
			//统计图装载
			if(this.param.web.viewType == "charts"){
				this.loadCharts();
			}
			
		}
		
		//装载响应式脚本
		if(this.param.act != undefined){
			this.loadAct();
		}
	},
	
	/* 装载响应式脚本 */
	loadAct:function(){
		//装载Tab类型后续脚本
		if(this.param.act.actType == "tab"){
			this.loadTabAct();
		}
	},
	
	/* 装载统计图信息 */
	loadCharts:function(){
		if(this.param.web.url == undefined){
			this.param.web.url = MUtil.getRootPath()+"/ReportService";
		}	
		var charts = new MonitorCharts(this.param.web);
		charts.load();
	},
	
	/* 装载标签页响应脚本 */
	loadTabAct:function(){
		
		//标签页响应默认值
		if(this.param.act.clickType == undefined){
			this.param.act.clickType = "#myTab li a";
		}
		//下拉式
		if(this.param.act.clickType == "drop"){
			this.param.act.clickType = "#myTab .dropdown-menu li a";
		}
		//扩展式
		else if(this.param.act.clickType == "nav"){
			this.param.act.clickType = "#myTab li a";
		}
		
		var self = this.self;
		
		$(this.param.act.clickType).unbind("click");
		$(this.param.act.clickType).click(function (e) {
			  
			  var hrefId = $(e.target).attr("href").substring(1);
			  
			  e.preventDefault();			    		   	  		    	  	    	  
			  var table = new Monitor();
			  
			  table.setParam(self.param);
			  
			  //填充新参数
			  if(self.param.act.msg != undefined){
				  table.appendParam(self.param.act.msg,e);
			  }
			  //填充标示信息
			  if(self.param.act.href != undefined){
				  var hrefs = self.param.act.href;
				  for(var i=0;i<hrefs.length;i++){
					  eval("table.param."+hrefs[i]+" = '"+hrefId+"';");
				  }				  
			  }
			  		  
			  table.loadHTML();	
			  
			  //后续方法调用
			  if(self.param.act.after != undefined){
				  self.param.act.after(e);
			  }
		});
	},
	
	/* 根据数据装载表格 */
	loadTable:function(rspBody){
		
		//视图转换,数据存储
		var msgTable = new MonitorTable(rspBody);
				
		//页面展现
		var msgTableView = new MonitorTableView(msgTable);
		msgTableView.setTableId(this.param.web.tableId);
		
		//设置标题颜色
		if(this.param.web.panelColor!=undefined){
			msgTableView.setPanelColor(this.param.web.panelColor);
		}
		
		//设置表格填充DIV标示
		if(this.param.web.divId!=undefined){
			msgTableView.setDivId(this.param.web.divId);
		}
		
		//设置是否清除表间距
		if(this.param.web.isPadding != undefined){
			msgTableView.setIsPadding(this.param.web.isPadding);
		}
		
		//按钮设置
		if(this.param.web.button != undefined){
			msgTableView.setButtons(this.param.web.button);
		}
		
		msgTableView.load();
		
	},
	
	/* 根据数据装载多个表格 */
	loadFixTable:function(rspBodyTable){
		
		//数据存储
		var msgTable = new MonitorTableFix(rspBodyTable);	
		//数据视图
		var msgView = new MonitorTableFixView(msgTable);
		
		//布局设置
		if(this.param.web.layout != undefined){
			msgView.setLayOut(this.param.web.layout);
		}
		
		//设置标题颜色
		if(this.param.web.panelColor!=undefined){
			msgView.setPanelColor(this.param.web.panelColor);
		}
		
		//设置表格填充DIV标示
		if(this.param.web.divId!=undefined){
			msgView.setDivId(this.param.web.divId);
		}
		
		//设置是否清除表间距
		if(this.param.web.isPadding != undefined){
			msgView.setIsPadding(this.param.web.isPadding);
		}
		
		//按钮设置
		if(this.param.web.button != undefined){
			msgView.setButtons(this.param.web.button);
		}
		
		msgView.load();
		
		msgView.loadAfter();
	},
	
	/* 装载标签页 */
	loadTab:function(rspBodyTab){		
		
		var msgTab = new MonitorTab(rspBodyTab);
		
		var msgTabView = new MonitorTabView(msgTab);
		
		//设置填充DIV标示
		if(this.param.web.divId!=undefined){
			msgTabView.setDivId(this.param.web.divId);
		}
		
		//设置标签页形式
		if(this.param.web.navType!=undefined){
			msgTabView.setNavType(this.param.web.navType);
		}
		
		msgTabView.load();
	},
	
	/* 装载装饰组件 */
	loadTag:function(rspBodyTag){
		var tagView = new MonitorTag(rspBodyTag);
		
		//设置Web信息
		tagView.setWeb(this.param.web);
		
		tagView.load();
	},
	
	/* 装载二列表组件 */
	loadMap:function(rspBodyMap){
		var mapView = new MonitorMapTable(rspBodyMap);
		
		mapView.setWeb(this.param.web);
		
		mapView.load();
	},
	
	/* 装载系统多选表组件  */
	loadNav:function(rspBodyNav){
		var navView = new MonitorNavTable(rspBodyNav);
		navView.setWeb(this.param.web);
		navView.load();
	}
		
};